package com.ctshk.rpc.finance.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ctshk.rpc.finance.dto.onaccount.OffAccountUsedListDTO;
import com.ctshk.rpc.finance.entity.FinanceOffAccountApply;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 财务销账申请记录 Mapper 接口
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-03-31
 */
public interface FinanceOffAccountApplyMapper extends BaseMapper<FinanceOffAccountApply> {

    /**
     * 预收明细-使用记录
     * @param accountId
     * @param iPage
     * @return
     */
    @Select("SELECT b.approval_status,a.currency_name,a.total_amount,a.exchange_rate,a.gmt_create,a.create_id\n" +
            "FROM t_finance_off_account_apply_detail a\n" +
            "LEFT JOIN t_finance_off_account_apply b ON a.apply_id = b.id\n" +
            "LEFT JOIN t_finance_on_account c ON b.on_account_id = c.id"+
            "WHERE c.account_id = #{account_id} AND b.use_advance_money = 1 AND b.is_deleted = 0 ORDER BY a.gmt_create DESC")
    Page<OffAccountUsedListDTO> queryUsedListByOnAccountId(@Param("account_id") Long accountId, @Param("iPage") Page<OffAccountUsedListDTO> iPage);
}
